from appium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


class Base:
    def __init__(self):
        cap={
                "platformName": "Android",
                "appium:deviceName": "emulator-5554",
                "appium:automationName": "uiautomator2",
                "appium:appPackage": "com.kongfz.app",
                "appium:appActivity": ".home.mvvm.homepage.HomeActivity",
                "appium:noReset": True
            }
        self.abc=webdriver.Remote('http://127.0.0.1:4723/wd/hub',cap)
        self.abc.implicitly_wait(10)
        # 定位元素
    def find_ele(self,loc):
        ele=self.abc.find_element(*loc)
        return ele
    def find_xian(self,loc):
        ele=WebDriverWait.until(EC.element_to_be_clickable(loc))
        loc=self.abc.find_element(ele)
        return loc
    def find_qingqiao(self,x,y):
        self.abc.tap([(x,y)],200)
    def find_huadong(self,a,b,c,d):
        self.abc.swipe(a,b,c,d,200)
    def find_fanhui(self):
        self.abc.press_keycode(4)
    def find_jieping(self,filename):
        self.abc.save_screenshot(filename)
    def tuichu(self):
        self.abc.quit()




